import yaml

def generate(fileInput, fileOutput):
    fInput = open(fileInput, 'r')
    fOutput = open(fileOutput, 'w')

    document = yaml.load(fInput)
    for data in document:
        title = data.lower()
        statement = 'create table ' + title + '(' + title + '_id serial, '
        fields = document[data]['fields']
        for column in fields:
            statement = statement + title + '_' + column + ' ' + fields[column] + ', '
        statement = statement[0:len(statement) - 2] + ');'
        fOutput.write(statement + '\n')
    fInput.close()
    fOutput.close()
    
if __name__ == '__main__':
    generate('file.txt', 'output.txt')
